package com.defangit.award.orm;

import com.defangit.award.domain.Award;
import com.defangit.award.domain.Prize;
import laogen.hibernate.CommonService;
import laogen.lang.exception.ParameterNotValidException;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * Created by zhangfagen on 2019/1/12.
 */
public class PrizeService extends CommonService<Prize> {
    public boolean addPrize(int awardId, List<Prize> prize){
        Award award=getSession().get(Award.class,awardId);
        if(award==null) throw ParameterNotValidException.zeroIdOrEntityNonExist("抽奖活动id");
        /*for(Prize prizelist :prize){
        prizelist.setAward(award);}*/
        prize.stream().forEach((prizelist)->{
            prizelist.setAward(award);
        });
        saveOrUpdate(prize);
        commitSession();
        return true;
    }

}
